<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');
class Authen_model extends MY_Model
{   //公司 认证信息中间表
    private $table = 'authen';
	public function __construct()
	{
		parent::__construct($this->table);
	
	}
	
	/**
	 *获取公司认证信息
	 * */
	public function getAuthen($companyId)
	{
	    $this->db->select('typeName as authenName');
	    $this->db->where('companyId',$companyId);
	    $this->db->join('type','type.typeId=authen.typeId');
	    $result = $this->db->get($this->table);
	    return $result->result_array();
	}	

	
    /**
     * 前台获取五条banner图
     * */
	public function getWebBannerList($where=array(), $select = '*',$limit=10,$start=0)
	{	
	    $this->db->where('typeFlag',0);
	    $this->db->where('menuId',0);
	    $this->db->order_by('displayOrder','asc')->order_by('bannerId','desc')->limit(5);
	    return $this->db->get( $this->table )->result_array();
	}
	
	/**
	 * 获取banner列表
	 * */
	public function getBannerList($where=array(), $select = '*',$limit=10,$start=0)
	{
	    $param = $this->_getWhere($where);
	    $this->db->select($select);
	    $this->db->where($param);
	    $this->db->order_by('displayOrder','asc')->limit($limit, $start);
	    return $this->db->get( $this->table )->result_array();
	}
	
	/**
	 * 获取全部banner列表
	 * */
	public function getBannerAllList()
	{	 
	    $this->db->order_by('displayOrder','asc');
	    return $this->db->get($this->table)->result_array();
	}

	
	/**
	 *获取单条数据
	 * */
	public function getBannerRow($bannerId=0)
	{
	    $this->db->where('bannerId', $bannerId);
	    $result = $this->db->get($this->table);
	    return $result->row_array();
	}
	
	/**
	 * 添加
	 * */
	public function insertData($userData)
	{
	    $res = $this->db->insert($this->table, $userData);
	    return $res;
	}
	
    /**
     * 修改
     * */

	public function setBannerByID($updateData, $bannerId)
	{
	    $this->db->where('bannerId', $bannerId);
	    return $this->db->update($this->table, $updateData);
	}
	
	/**
	 * 获取总条数
	 * */
	public function getBannerCount($where=array())
	{
	    $param = $this->_getWhere($where);
	    $this->db->where($param);
	    return $this->db->count_all_results( $this->table );
	}
	
	/**
	 * 查询条件
	 * */
	public function _getWhere( $where=array() )
	{
	    $param = array();
	    
	    if (!empty($where['bannerName']))
	    {
	        $param['bannerName like'] = '%'.strval($where['bannerName']).'%';
	    }
	 
	
	    return $param;
	}
	
	/**
	 * 验证唯一
	 * */
	public function checkUnique($name,$bannerId=0)
	{
	    $this->db->where('bannerName', $name);
	    if(!empty($bannerId))
	    {
	        $this->db->where('bannerId !=', $bannerId);
	    }
	    $result = $this->db->get($this->table);
	    return $result->row_array();
	}
	
	/**
	 * 删除用户
	 * */
	public function delete( $bannerId )
	{
	    $this->db->where( 'bannerId', $bannerId );
	    $query = $this->db->delete( $this->table);
	    return $query ? $bannerId : false;
	}
	
	/**
	 * 获取底部广告
	 * */
	public function getFooterBanner()
	{
	    $this->db->where('menuId', 0);
	    
	    $this->db->where('typeFlag ', 1);
	    
	    $result = $this->db->get($this->table);
	    return $result->row_array();
	}
	
	
	public function getActivityBannerList()
	{
	    $this->db->where('typeFlag',0);
	    $this->db->where('menuId',6);
	    $this->db->order_by('displayOrder','asc')->order_by('bannerId','desc')->limit(5);
	    return $this->db->get( $this->table )->result_array();
	}
}
?>